<?php

$pageParentID = "";

$pageSection = "";

if(@$_GET["id"]){
	
	#Get page id
	$pageParentID = $_GET["id"];
}

if(@$_GET["section"]){

	#Get page section
	$pageSection = $_GET["section"];
}

#initialize output variable
$output = "";

$output .= "<table cellspacing=\"0\" align=\"left\">";

#distinguish junkbox section and others
if($pageSection != 'Recycle Bin'){
	
	#Get pages according to the given section
	$PAGES = PageData::getSectionPages($pageSection,$pageParentID);

	if(!empty($pageParentID)){

		#Get page ids
		foreach($PAGES -> getPageIDs() as $page_id){
			
			#Get page pointer
			$obPage =  $PAGES -> getPage($page_id);
			
			#Only for the children of current selected page parent
			if($obPage -> getData('p_parent') == $pageParentID){
				
				//$flagHasChildren = $PAGES -> getPagesWithValues(array("p_parent"), array($value));
				
				#If those page` children is not empty, show it as a folder, other wise show it as a file
				if(count($obPage -> getData('p_children')) > 0){
				
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><div class=\"admin_pages_closed_dir\" onclick=\"onlick_expandParentPage('".$pageSection."',this,'".$page_id."');\"></div></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$page_id."\" href=\"../" . $pageSection . "/" . $page_id . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($obPage -> getData("p_status"))."','".$page_id."')\" onclick=\"\" style=\"text-decoration:none;\">".$obPage -> getData("p_name")."(".$page_id.")"."</a><br/><div align=\"left\" id=\""."div_".$page_id."\"></div></td></tr>";
				}
				else{
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><div class=\"admin_pages_doc\"></div></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$page_id."\" href=\"../" . $pageSection . "/" . $page_id . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($obPage -> getData("p_status"))."','".$page_id."')\" onclick=\"\" style=\"text-decoration:none;\">".$obPage -> getData("p_name")."(".$page_id.")"."</a><br/></td></tr>";
				}
			}
		}
	}
	else{ 
		
		#Get page ids
		foreach($PAGES -> getPageIDs() as $page_id){
			
			#Get page pointer
			$obPage =  $PAGES -> getPage($page_id);
			
			#Only for the children of current selected page parent
			if($obPage -> getData('p_parent')==''){
				
				#If those page` children is not empty, show it as a folder, other wise show it as a file
				if(count($obPage -> getData('p_children')) > 0){
					
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><div class=\"admin_pages_closed_dir\" onclick=\"onlick_expandParentPage('".$pageSection."',this,'".$page_id."');\"></div></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$page_id."\" href=\"../" . $pageSection . "/" . $page_id . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($obPage -> getData("p_status"))."','".$page_id."')\" onclick=\"\" style=\"text-decoration:none;\">".$obPage -> getData("p_name")."(".$page_id.")"."</a><br/><div align=\"left\" id=\""."div_".$page_id."\"></div></td></tr>";
				}
				else{
						
					$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><div class=\"admin_pages_doc\"></div></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
				
					$output.="<a target=\"_blank\" id=\"a_".$page_id."\" href=\"../" . $pageSection . "/" . $page_id . ".php\" onmouseover=\"ShowControlPanel('".getPageStatusName($obPage -> getData("p_status"))."','".$page_id."')\" onclick=\"\" style=\"text-decoration:none;\">".$obPage -> getData("p_name")."(".$page_id.")"."</a><br/></td></tr>";
				}
			}	
			
		}

	}
}
else{
	
	#pages which are belongint to junkbox
	$recycledData = PageData::getRecycledPages();
	
	if(count($recycledData) > 0){	
	
		foreach($recycledData as $key => $value){
				
			$output.="<tr><td valign=\"top\" style=\"border-color: white;border-style: solid;\"><div class=\"admin_pages_doc\"></div></td><td style=\"border-color: white;border-style: solid;\" align=\"left\">";
					
			$output.="<a target=\"_blank\" id=\"a_".$value["p_id"]."_junk\" onmouseover=\"ShowJunkboxControlPanel('".getPageStatusName($value["p_status"])."','".$value["p_id"]."')\" onclick=\"\" style=\"text-decoration:none;\">".$value["p_name"]."(".$value["p_id"].")"."</a><br/><div align=\"left\" id=\""."div_".$value["p_id"]."_junk\"></div></td></tr>";
		}
	}
}

$output .= "</table>";

addContent($output);
?>